package org.svnadmin.common.util;

/**
 * 字符串工具类
 *
 * @author hewenjie
 * @data 2021/6/10
 */
public class StrUtil{

    /**
     * 给字符串加单引号
     * @param val String
     * @return String
     */
    public static String apostrophe(String val){
        if(val.contains(",")){
            StringBuilder sb = new StringBuilder();
            String[] arr = val.split(",");
            for (int i = 0; i <arr.length ; i++) {
                if(i==arr.length-1){
                    sb.append("'").append(wipe(arr[i])).append("'");
                }else {
                    sb.append("'").append(wipe(arr[i])).append("'").append(",");
                }
            }
            return sb.toString();
        }
        return "'"+wipe(val)+"'";
    }

    /**
     * 去除空格，换行，制表符等特殊字符
     * @param  str String
     * @return String
     */
    public static String wipe(String str){
        return str.replaceAll("[\n|\r]+", "").replace("\t","").trim();
    }



}
